<?php

namespace App\Repositories;


use App\Interfaces\用户ID;
use App\Repositories\SmsRepository;
use App\Models\Address;
use App\Models\User;
use App\Interfaces\MyService;


class MyRepository implements MyService{



    /**
     *
     * 获取用户地址
     * @param $user_id          用户ID
     *             
     */

    public function getAddress($user_id){

    }


    /**
     *
     * 找回密码
     * @param $phone            手机号
     * @param $newPaw           新密码
     *
     * @throws
     * @return bool
     */

    public function findPaw($phone,$newPaw){


            $user = User::where('phone',$phone)->update(['password'=>md5($newPaw)]);
       // dd(User::where('password',md5($newPaw))->get());
            return $user;


    }


    /**
     *
     * 修改用户密码
     *
     * @param $user_name          用户名
     * @param $oldPassword
     * @param $newPassword
     * @throws
     * @return mixed
     */

    public function updatePaw($user_name,$oldPassword,$newPassword){


        $is_exit = User::where('user_name', $user_name)->where('Password', md5($oldPassword))->get();
        //dd("daf");
        if($is_exit){
            $user = User::where('user_name', $user_name)->where('Password', md5($oldPassword))->update(['password'=>md5($newPassword)]);
            return $user;

        }else{

            throw Exception("该用户不存在！");
            //return false;
        }


    }


}